<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%
	/*************************************************************/
	/*	[getParam]
		param: journey
		journey는 localstorage의 req에 담겨있는 많은 경로 정보수들중
		몇번째 route 인지 알 수 있는 번호 정보가 담겨있다.*/			
	/*************************************************************/
	String journey = request.getParameter("journey");
%>
<!DOCTYPE html>
<html lang=ko>
<head>
<%@ include file = "head.jsp" %>
<link rel=stylesheet type=text/css href=assets/css/alarm-page-style.css />
<script src=assets/js/jquery.js></script>
<script src=assets/js/bootstrap.min.js></script>
<title>alarm-page</title>
</head>
<body>
<form id=sr-to-ap name=sr-to-ap role=form method=post action=rout.jsp>
<nav class="navbar navbar-fixed-top" role=navigation>
<div class="nav_content text-center">
<div class=pull-left>
<div class="nav_menu_btn pull-left text-center">
<a class=back_btn onclick=history.back()><i class="fa fa-arrow-left"></i></a>
</div>
</div>
<span class=page_title><strong>알람설정</strong></span>
<div class="submit_btn pull-right text-center">
<a href="javascript:$('#sr-to-ap').submit()">완료</a>
</div>
</div>
</nav>
<div class=info_bar>
<div class=content>
<div class=sub-header-box>
<input type=hidden name=journey value="<%=journey%>"/>
<span class=info_txt>
<span class="text-info info_icon"><i class="fa fa-clock-o"></i></span>
<strong><span id=duration class=text-danger></span>, </strong>
<strong>도착예정: <span id=arrival_time></span></strong><span></span>
</span>
<button id=viewmap type=button class="btn btn-info btn-xs pull-right see_map">지도보기</button>
</div>
</div>
</div>
<div class="list-box panel-group">
</div>
</form>
<script type=text/javascript>var key=new Date().getTime()+""+<%=journey%>;var response=JSON.parse(sessionStorage.req);while(localStorage.length>=10){var dkey=localStorage.key(0);localStorage.removeItem(dkey)}var legs=response.routes[<%=journey.substring(13, 14)%>].legs[0];legs.start_address=sessionStorage.sl;legs.end_address=sessionStorage.el;var is_legs=false;if(localStorage.length>0){for(var i=0;i<localStorage.length;i++){if(localStorage.getItem(localStorage.key(i))==JSON.stringify(legs)){sessionStorage.journey_key=localStorage.key(i);is_legs=true}if(i==(localStorage.length-1)&&is_legs==false){sessionStorage.journey_key=key;localStorage[key]=JSON.stringify(legs)}}}else{if(localStorage.length==0){localStorage[key]=JSON.stringify(legs);sessionStorage.journey_key=key}}var al_info=new Array(legs.steps.length+1);var is_al=new Array(legs.steps.length+1);for(var i=0;i<legs.steps.length+1;i++){if(i==0){is_al[i]=1}else{if(legs.steps[i-1].travel_mode==("WALKING")){is_al[i]=0}else{is_al[i]=1}}}window.sessionStorage.setItem("is_al",is_al);var alarmDB={};alarmDB.webdb={};alarmDB.webdb.db=null;var dbSize=1*1024*1024;alarmDB.webdb.db=openDatabase("alarmDB","1.0","알람DB",dbSize);var journeyAlDB=openDatabase("JourneyAlDB","1.0","내 루트 알람DB",dbSize);journeyAlDB.transaction(function(a){a.executeSql("CREATE TABLE IF NOT EXISTS journeyAlDB(key, is_al, al_info)")});journeyAlDB.itemInsert=function(a,b){journeyAlDB.transaction(function(c){c.executeSql("SELECT * FROM journeyAlDB WHERE key=?",[sessionStorage.journey_key],function(d,e){if(e.rows.length<1){journeyAlDB.transaction(function(f){f.executeSql("INSERT INTO journeyAlDB(key, is_al, al_info) VALUES (?,?,?)",[sessionStorage.journey_key,a,b],function(){},function(g,h){console.log(h.message)})})}})})};journeyAlDB.itemUpdate=function(b,a){journeyAlDB.transaction(function(c){c.executeSql("UPDATE journeyAlDB SET "+b+"=? WHERE key=?",[a,localStorage.key(localStorage.length-1)])})};journeyAlDB.itemDelete=function(a){journeyAlDB.transaction(function(b){b.executeSql("DELETE FROM journeyAlDB WHERE key=?",[a],function(){},function(c,d){console.log(d.message)})})};journeyAlDB.transaction(function(a){a.executeSql("SELECT count(*) as cnt FROM journeyAlDB",[],function(b,c){var d=c.rows.item(0)["cnt"];if(d>=10){b.executeSql("SELECT key FROM journeyAlDB",[],function(e,f){var g=f.rows.item(0)["key"];journeyAlDB.itemDelete(g)},function(f,g){console.log(g.message)})}},function(b,c){console.log(c.message)})});var time=new Date();var hh=time.getHours();var mm=time.getMinutes();var dt=legs.departure_time.text.split(" ");var dtime=dt[1].split(":");var ampm=dt[0];var dhh=dtime[0];var dmm=dtime[1];if(ampm=="오후"){if(dhh==12){dhh=12}else{dhh=Number(dhh)+12}}else{if(ampm=="오전"){if(dhh==12){dhh=0}}}function isBtnClick(){if(hh>dhh){$("#altime20btn").attr("disabled","disable");$("#altime20btn").removeClass("btn-primary");$("#altime15btn").attr("disabled","disable");$("#altime15btn").removeClass("btn-success");$("#altime10btn").attr("disabled","disable");$("#altime10btn").removeClass("btn-warning");$("#altime5btn").attr("disabled","disable");$("#altime5btn").removeClass("btn-danger");$("#alinfotxt").html('알람설정: <span class="text-warning">알람을 설정할 수 없습니다.</span>');$("#alth_box").html('<span class="alarm-thumbnail text-muted"><i class="fa fa-circle-o"></i></span>');is_al[0]=0}else{if(hh==dhh){if(mm+20>=dmm){$("#altime20btn").attr("disabled","disable");$("#altime20btn").removeClass("btn-primary");$("#alinfotxt").html('알람설정: 출발 <span class="text-warning">15분전</span>');if(mm+15>=dmm){$("#altime15btn").attr("disabled","disable");$("#altime15btn").removeClass("btn-success");$("#alinfotxt").html('알람설정: 출발 <span class="text-warning">10분전</span>');if(mm+10>=dmm){$("#altime10btn").attr("disabled","disable");$("#altime10btn").removeClass("btn-warning");$("#alinfotxt").html('알람설정: 출발 <span class="text-warning">5분전</span>');if(mm+5>=dmm){$("#altime5btn").attr("disabled","disable");$("#altime5btn").removeClass("btn-danger");$("#alinfotxt").html('알람설정: <span class="text-warning">알람을 설정할 수 없습니다.</span>');$("#alth_box").html('<span class="alarm-thumbnail text-muted"><i class="fa fa-circle-o"></i></span>');is_al[0]=0}}}}}else{if(hh<dhh){if(mm+20>=60){if(-40>=dmm-mm){$("#altime20btn").attr("disabled","disable");$("#altime20btn").removeClass("btn-primary");$("#alinfotxt").html('알람설정: 출발 <span class="text-warning">15분전</span>');if(-45>=dmm-mm){$("#altime15btn").attr("disabled","disable");$("#altime15btn").removeClass("btn-success");$("#alinfotxt").html('알람설정: 출발 <span class="text-warning">10분전</span>');if(-50>=dmm-mm){$("#altime10btn").attr("disabled","disable");$("#altime10btn").removeClass("btn-warning");$("#alinfotxt").html('알람설정: 출발 <span class="text-warning">5분전</span>');if(-55>=dmm-mm){$("#altime5btn").attr("disabled","disable");$("#altime5btn").removeClass("btn-danger");$("#alinfotxt").html('알람설정: <span class="text-warning">알람을 설정할 수 없습니다.</span>');$("#alth_box").html('<span class="alarm-thumbnail text-muted"><i class="fa fa-circle-o"></i></span>');is_al[0]=0}}}}}}}}window.sessionStorage.setItem("is_al",is_al);journeyAlDB.itemUpdate("is_al",is_al)}function html_getAlset(b,a){if(b==0){$("#altime"+b).html(a+"분전")}else{$("#altime"+b).html(a+"m전")}al_info[b]=a;window.sessionStorage.setItem("al_info",al_info);journeyAlDB.itemUpdate("al_info",al_info)}function setAlthumb(a){$("#althumb"+a).toggleClass("text-danger");$("#althumb"+a).toggleClass("text-muted");if(is_al[a]==1){is_al[a]=0}else{is_al[a]=1}window.sessionStorage.setItem("is_al",is_al);journeyAlDB.itemUpdate("is_al",is_al)}function setColhidden(a){if(a==0){if(hh>dhh){$("#collapse"+a).addClass("hidden")}else{if(hh==dhh){if(mm+5>=dmm){$("#collapse"+a).addClass("hidden")}}else{if(hh<dhh){if((mm+5-60-dmm)>=dmm){$("#collapse"+a).addClass("hidden")}}}}}else{if(a>0){if(legs.steps[a-1].travel_mode==("WALKING")){$("#collapse"+a).addClass("hidden")}}}}function html_getAlDB(){alarmDB.webdb.db.transaction(function(a){var b="SELECT * FROM alarmDB";a.executeSql(b,[],function(c,d){for(var f=0;f<d.rows.length;f++){if(d.rows.item(f).key=="is_alarm"){if(d.rows.item(f).value=="false"){for(var e=0;e<legs.steps.length+1;e++){$("a#althumb"+e).removeClass("text-danger");$("a#althumb"+e).addClass("text-muted");is_al[e]=0;window.sessionStorage.setItem("is_al",is_al);journeyAlDB.itemUpdate("is_al",is_al)}}}else{if(d.rows.item(f).key=="set_time"){if(d.rows.item(f).value==5){$("#altime0").html("5분전");al_info[0]=5}else{if(d.rows.item(f).value==10){$("#altime0").html("10분전");al_info[0]=10}else{if(d.rows.item(f).value==15){$("#altime0").html("15분전");al_info[0]=15}else{if(d.rows.item(f).value==20){$("#altime0").html("20분전");al_info[0]=20}}}}}else{if(d.rows.item(f).key=="set_dis"){if(d.rows.item(f).value==30){for(var e=1;e<legs.steps.length+1;e++){if(legs.steps[e-1].travel_mode!=("WALKING")){$("#altime"+e).html("30m전")}al_info[e]=30}}else{if(d.rows.item(f).value==50){for(var e=1;e<legs.steps.length+1;e++){if(legs.steps[e-1].travel_mode!=("WALKING")){$("#altime"+e).html("50m전")}al_info[e]=50}}else{if(d.rows.item(f).value==100){for(var e=1;e<legs.steps.length+1;e++){if(legs.steps[e-1].travel_mode!=("WALKING")){$("#altime"+e).html("100m전")}al_info[e]=100}}else{if(d.rows.item(f).value==150){for(var e=1;e<legs.steps.length+1;e++){if(legs.steps[e-1].travel_mode!=("WALKING")){$("#altime"+e).html("150m전")}al_info[e]=150}}}}}}}}}window.sessionStorage.setItem("al_info",al_info);journeyAlDB.itemUpdate("al_info",al_info)})})}$(function(){var b="";for(var a=0;a<legs.steps.length+1;a++){b+='<div class="list-case">';b+='<div class="content">';b+="<div>";b+='<div class="panel-heading">';b+='<div class="panel-title">';b+="<div>";if(a==0){b+='<span id="alth_box"><a id="althumb'+a+'" class="alarm-thumbnail text-danger" onclick="setAlthumb('+a+')"><i class="fa fa-clock-o"></i></a></span>';b+='<a class="list-inner'+a+' list-style" data-toggle="collapse" data-parent="#accordion" href="#collapse'+a+'" onclick="setColhidden('+a+')">';b+="<div>";b+='<span class="text-muted">Step. '+(a+1)+" </span>";if(legs.steps[a].travel_mode==("WALKING")){b+='<img class="icon-pos" style="height: 20px; width: 20px" src="http://maps.gstatic.com/mapfiles/transit/iw/6/walk.png">'}else{b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a].transit.line.vehicle.icon+'">'}b+="</div>";b+='<div class="loca-name">';if(legs.steps[a].travel_mode==("WALKING")){b+='<img class="icon-pos" style="height: 20px; width: 20px" src="http://maps.gstatic.com/mapfiles/transit/iw/6/walk.png">'}else{b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a].transit.line.vehicle.icon+'">'}b+=sessionStorage.getItem("sl")+"에서 출발";b+="</div>";b+='<div class="sub_info">출발시간: <strong>'+legs.departure_time.text+"</strong></div>";b+='<div class="sub_info" id="alinfotxt"><span>알람설정: 출발 <span id="altime'+a+'" class="text-warning">10분</span></span></div>';b+="</a>";al_info[a]=10}else{if(legs.steps[a-1].travel_mode!=("WALKING")){b+='<a id="althumb'+a+'" class="alarm-thumbnail text-danger" onclick="setAlthumb('+a+')"><i class="fa fa-clock-o"></i></a>'}else{b+='<span class="alarm-thumbnail text-muted"><i class="fa fa-circle-o"></i></span>'}b+='<a class="list-inner'+a+' list-style" data-toggle="collapse" data-parent="#accordion" href="#collapse'+a+'" onclick="setColhidden('+a+')">';b+="<div>";b+='<span class="text-muted">Step. '+(a+1)+" </span>";if(legs.steps[a-1].travel_mode==("WALKING")){b+='<img class="icon-pos" style="height: 20px; width: 20px" src="http://maps.gstatic.com/mapfiles/transit/iw/6/walk.png">'}else{b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a-1].transit.line.vehicle.icon+'">'}b+='<strong class="text-danger">'+legs.steps[a-1].duration.text+"</strong>";b+="</div>";if(legs.steps[a-1].travel_mode!=("WALKING")){b+='<div class="loca-name">';b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a-1].transit.line.vehicle.icon+'">';b+='<span class="icon-pos2" style="background-color:'+legs.steps[a-1].transit.line.color+'; padding:1px 4px 0px 4px; color: #ffffff"><strong>'+legs.steps[a-1].transit.line.short_name+"</strong></span>";b+=legs.steps[a-1].transit.departure_stop.name+' <i class="fa fa-caret-right"></i> ';b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a-1].transit.line.vehicle.icon+'">';b+=legs.steps[a-1].transit.arrival_stop.name;b+="</div>";b+='<div class="sub_info">출발시간: <strong>'+legs.steps[a-1].transit.departure_time.text+"</strong></div>";b+='<div class="sub_info"><span>알람설정: <img class="icon-pos1" style="height: 12px; width: 12px" src="'+legs.steps[a-1].transit.line.vehicle.icon+'">'+legs.steps[a-1].transit.arrival_stop.name+' 도착 <span id="altime'+a+'" class="text-warning">100m전</span></span></div>'}else{if(a==1){b+='<div class="loca-name">';b+='<img class="icon-pos" style="height: 20px; width: 20px" src="http://maps.gstatic.com/mapfiles/transit/iw/6/walk.png">';b+=sessionStorage.getItem("sl")+' <i class="fa fa-caret-right"></i> ';b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a].transit.line.vehicle.icon+'">';b+=legs.steps[a].transit.departure_stop.name;b+="</div>";b+='<div class="sub_info">출발시간: <strong>'+legs.departure_time.text+"</strong></div>";b+='<div class="sub_info"><span>알람설정: <span id="altime'+a+'" class="text-warning">도보 시 알람을 설정할 수 없습니다.</span></span></div>'}else{b+='<div class="loca-name">';b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a-2].transit.line.vehicle.icon+'">';b+=legs.steps[a-2].transit.arrival_stop.name+' <i class="fa fa-caret-right"></i> ';if(a+1<legs.steps.length+1){b+='<img class="icon-pos" style="height: 20px; width: 20px" src="'+legs.steps[a].transit.line.vehicle.icon+'">';b+=legs.steps[a].transit.departure_stop.name}else{b+=sessionStorage.getItem("el")}b+="</div>";b+='<div class="sub_info">출발시간: <strong>'+legs.steps[a-2].transit.arrival_time.text+"</strong></div>";b+='<div class="sub_info"><span>알람설정: <span id="altime'+a+'" class="text-warning">도보 시 알람을 설정할 수 없습니다.</span></span></div>'}}al_info[a]=100;b+="</a>"}b+="</div>";b+="</div>";b+="</div>";b+="</div>";b+="</div>";b+='<div id="collapse'+a+'" class="panel-collapse collapse">';b+='<div class="panel-body row">';if(a==0){b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button id="altime20btn" class="btn btn-primary albtns" onclick="html_getAlset('+a+',20); return false;">20분전</button></span>';b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button id="altime15btn" class="btn btn-success albtns" onclick="html_getAlset('+a+',15); return false;">15분전</button></span>';b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button id="altime10btn" class="btn btn-warning albtns" onclick="html_getAlset('+a+',10); return false;">10분전</button></span>';b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button id="altime5btn" class="btn btn-danger albtns" onclick="html_getAlset('+a+',5); return false;">5분전</button></span>'}else{b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button class="btn btn-primary albtns" onclick="html_getAlset('+a+',150); return false;">150m전</button></span>';b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button class="btn btn-success albtns" onclick="html_getAlset('+a+',100); return false;">100m전</button></span>';b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button class="btn btn-warning albtns" onclick="html_getAlset('+a+',50); return false;" >50m전</button></span>';b+='<span class="padding5 col-md-3 col-sm-3 col-xs-3"><button class="btn btn-danger albtns" onclick="html_getAlset('+a+',30); return false;">30m전</button></span>'}b+="</div>";b+="</div>";b+="</div>";window.sessionStorage.setItem("al_info",al_info)}$(".list-box").html(b);$("#start_address").html(legs.start_address);$("#end_address").html(legs.end_address);$("#departure_time").html(legs.departure_time.text);$("#arrival_time").html(legs.arrival_time.text);$("#duration").html(legs.duration.text);$("#viewmap").click(function(){var c="";c+="journey.jsp";c+="?start=";c+=legs.start_location.nb+","+legs.start_location.ob;c+="&end=";c+=legs.end_location.nb+","+legs.end_location.ob;c+="&time=";c+=<%=journey.substring(0, 10)%>;c+="&journey=";c+=<%=journey.substring(13, 14)%>;location.href=c});html_getAlDB();isBtnClick();journeyAlDB.itemInsert(is_al,al_info)});</script>
</body>
</html>